class main {
    public String getPermutation(int n, int k) {
        boolean[] v = new boolean[n + 1];
        int d = 1;
        for (int i = 2; i < n; ++ i) d *= i;

        StringBuilder sb = new StringBuilder();
        -- k;

        for (int i = 1; i <= n; ++ i) {
            int m = k / d;
            for (int j = 1; j <= n; ++ j) {
                if (v[j]) continue;
                if (m -- == 0) {
                    sb.append(j);
                    v[j] = true;
                    break;
                }
            }
            k %= d;
            if (n - i > 0) d /= n - i;
        }

        return sb.toString();
    }
}